const app = getApp()
Page({
  data: {
    bank: {
      money: 0,
    },
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getBank();
  },
  /**
   * 读取我的账单
   */
  getBank: function () {
    var param = {
      'signkey': app.util().getRandom(12)
    }
    app.api().Get("api/v4/allwin/bank/index",param,(result) =>{
      if (result.code == 200) {
        this.setData({
          bank: result.data
        });
      }
    })
  },
  /**
   * 申请提现
   */
  onSubmit: function (e) {
    let that = this;
    var data = e.detail.value;
    //安全密码
    if (app.util().isNull(data.safepassword)) {
      wx.showModal({
        content: '安全密码必须填写'
      })
      return;
    }
    if (app.util().isNull(data.money)) {
      wx.showModal({
        content: '转入金额必须填写'
      })
      return;
    } else {
      if (!(/^\d+$/.test(data.money))) {
        wx.showModal({
          content: '转入金额只能输入整数'
        })
        return;
      } else {
        if (data < 100) {
          wx.showModal({
            content: '最小转入金额100元'
          })
          return;
        }
      }
    }
    //提交数据
    wx.showLoading({
      title: '提交申请中',
      mask: true
    })
    var parms = {
      money: data.money,
      safepassword: data.safepassword,
    }
    app.api().Post('api/v4/allwin/bank/recharge', parms, function (rel) {
      app.doWechatPay(rel.data, function (res) {
        wx.navigateBack({
          delta: 1
        })
      }, function (res) {
        wx.showModal({content:'充值失败', showCancel: false })
      });
    })
  }
})